const puppeteer = require('puppeteer');

// var url = 'https://tyrz.gd.gov.cn/tif/sso/static/?client_id=szjxgcxt&redirect_uri=https%3A%2F%2Famr.sz.gov.cn%2Fpsout%2Fjsp%2Fgcloud%2Fpubservice%2Fuserstsso%2Fgodeal.jsp&response_type=code&scope=all&service=initService';
var url = 'https://amr.sz.gov.cn/psout/jsp/gcloud/pubservice/network/apply_manage.jsp';

puppeteer.launch().then(async browser => {
  const page = await browser.newPage();
  await page.setViewport({
    width: 1920,
    height: 1080
  });
  // const aDom = await page.$('.login-tab:nth-child(1)');
  // aDom.click();
  await page.setCookie({
    name: "accessToken",
    value: "17cb3599-72a0-4616-8534-c7aafe6e9416@node3",
    expires: 1000 * 3600,
    url: "https://amr.sz.gov.cn"
  }, {
    name: "gdbsTokenId",
    value:"AQIC5wM2LY4SfczdrtM6JdNl1R3m4G7zAfRt27YfeA5F9PA.*AAJTSQACMTAAAlNLABQtODkwMzM0ODE4MTE4NzkwMTYzNg..*@node3",
    expires: 1000 * 3600,
    url: "https://amr.sz.gov.cn"
  }, {
    name: "isCaUser",
    value: "true",
    expires: 1000 * 3600,
    url: "https://amr.sz.gov.cn"
  },{
    name: "ishelp",
    value: "false",
    expires: 1000 * 3600,
    url: "https://amr.sz.gov.cn"
  }, {
    name: "isSameUser",
    value: "482215F9EAEDA9F4EFA5114EBA8C0CD0",
    expires: 1000 * 3600,
    url: "https://amr.sz.gov.cn"
  },{
    name: "JSESSIONID",
    value: "0000Lib8I6tmaCdROGfh_sEYppB:-1",
    expires: 1000 * 3600,
    url: "https://amr.sz.gov.cn"
  },{
    name: "psout_sso_token",
    value: "Lib8I6tmaCdROGfh_sEYppB",
    expires: 1000 * 3600
  },{
    name: "sangfor_cookie",
    value: "20126465",
    expires: 1000 * 3600
  },{
    name: "userType",
    value: "1"
  });
  await page.goto(url);
  await page.waitForTimeout(3000);
  await page.screenshot({path: 'screenshot.png'});
  // const aDom = await page.$('.btn-primary:nth-child(1)');
  // aDom.click();
  // await page.waitForTimeout(3000);
  // await page.screenshot({path: 'screenshot2.png'});
  // const page2 = ( await browser.pages() )[2];
  // await page2.screenshot({path: 'screenshot.png'});
  // const text = await page.$eval('.login-tab', el => el.textContent);

  // console.log(text); 
  await browser.close();
});
/*

(async () => {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  await page.setViewport({
    width: 1920,
    height: 1080
  });
  await page.goto('https://tyrz.gd.gov.cn/tif/sso/static/?client_id=szjxgcxt&redirect_uri=https%3A%2F%2Famr.sz.gov.cn%2Fpsout%2Fjsp%2Fgcloud%2Fpubservice%2Fuserstsso%2Fgodeal.jsp&response_type=code&scope=all&service=initService');
  await page.screenshot({path: 'screenshot.png'});
  // const aDom = await page.tap('.login-tab');
  // console.log(aDom.text()); 
  // await page.waitFor(3000);
  // const page2 = ( await browser.pages() )[2];
  // await page2.setViewport({width:1280,height:800});
  // console.log(await page2.$('span.nums_text'));
  // Get the "viewport" of the page, as reported by the page.
  // const dimensions = await page.evaluate(() => {
  //   return {
  //     width: document.documentElement.clientWidth,
  //     height: document.documentElement.clientHeight,
  //     deviceScaleFactor: window.devicePixelRatio
  //   };
  // });
 
  // console.log('Dimensions:', dimensions);
 
  await browser.close();
})();
*/

// 13603081006